package eric.wiki.wikiParser;

import info.bliki.wiki.dump.IArticleFilter;
import info.bliki.wiki.dump.Siteinfo;
import info.bliki.wiki.dump.WikiArticle;
import info.bliki.wiki.dump.WikiXMLParser;

import org.xml.sax.SAXException;

/**
 * Demo application which reads a compressed or uncompressed Wikipedia XML dump
 * file (depending on the given file extension <i>.gz</i>, <i>.bz2</i> or
 * <i>.xml</i>) and prints the title and wiki text.
 * 
 */
public class WikiDumpParser {
	
	static int num_of_field = 4;
	
	static private String[] WikiDoc = new String[num_of_field];
	
	/**
	 * Print get single wiki pages in the dump.
	 * 
	 */
	static class WikiArticleFilter implements IArticleFilter {

		public void process(WikiArticle page, Siteinfo siteinfo)
				throws SAXException {
			WikiDoc[0] = page.getId();
			WikiDoc[1] = page.getTitle();
			WikiDoc[2] = page.getTimeStamp();
//			WikiDoc[3] = page.getText();
			
			for (String test : WikiDoc) {
				System.out.println(test);
			}
			System.out.println("---------------------------------------");
			
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length != 1) {
			System.err.println("Usage: Parser <XML-FILE>");
			System.exit(-1);
		}
		String WikiFilename = args[0];
		try {
			IArticleFilter handler = new WikiArticleFilter();
			WikiXMLParser wxp = new WikiXMLParser(WikiFilename, handler);
			wxp.parse();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
